package controller

import (
	"github.com/gin-gonic/gin"
	"learning/gooop/spring/demo/framework/bean"
)

type IControllerBeanContext interface {
	bean.IBeanContext

	Apply(r *gin.Engine)
}

type tDefaultControllerBeanContext struct {
	bean.DefaultBeanContext
}

func (me *tDefaultControllerBeanContext) init() {
	me.DefaultBeanContext = *bean.NewDefaultBeanContext()
}

func (me *tDefaultControllerBeanContext) Apply(r *gin.Engine) {
	for _, it := range me.All() {
		if controller, ok := it.(IRestController); ok {
			controller.RegisterRestController(r)
		}
	}
}

func newDefaultControllerBeanContext() IControllerBeanContext {
	it := new(tDefaultControllerBeanContext)
	it.init()
	return it
}

var ControllerBeanContext = newDefaultControllerBeanContext()
